package com.bootdo.system.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.system.domain.PayDeatailsDO;
import com.bootdo.system.service.PayDeatailsService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.common.utils.ShiroUtils;

/**
 * 
 * @ClassName: DealSlideshowController  
 * @Description: TODO(速用币明细控制类)  
 * @author lzy  
 * @date 2018年9月18日  
 *
 */
 
@Controller
@RequestMapping("/system/payDeatails")
public class PayDeatailsController {
	@Autowired
	private PayDeatailsService payDeatailsService;
	
	@GetMapping()
	@RequiresPermissions("system:payDeatails:payDeatails")
	String PayDeatails(){
	    return "system/payDeatails/payDeatails";
	}
	
	@ResponseBody
	@GetMapping("/list")
	//@RequiresPermissions("system:payDeatails:payDeatails")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
		System.out.println("开始时间"+params.get("beginDate"));
		System.out.println("结束时间"+params.get("endDate"));
		params.put("userId",ShiroUtils.getUserId());
        Query query = new Query(params);
		List<PayDeatailsDO> payDeatailsList = payDeatailsService.list(query);
		int total = payDeatailsService.count(query);
		PageUtils pageUtils = new PageUtils(payDeatailsList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:payDeatails:add")
	String add(){
	    return "system/payDeatails/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("system:payDeatails:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		PayDeatailsDO payDeatails = payDeatailsService.get(id);
		model.addAttribute("payDeatails", payDeatails);
	    return "system/payDeatails/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	//@RequiresPermissions("system:payDeatails:add")
	public R save( PayDeatailsDO payDeatails){
		if(payDeatailsService.save(payDeatails)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:payDeatails:edit")
	public R update( PayDeatailsDO payDeatails){
		payDeatailsService.update(payDeatails);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:payDeatails:remove")
	public R remove( Integer id){
		if(payDeatailsService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:payDeatails:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		payDeatailsService.batchRemove(ids);
		return R.ok();
	}
	
}
